/*
 *             Copyright (C) 2024 Steve Jrong
 * 
 * 	   GitHub Homepage: https://www.github.com/SteveJrong
 *      Gitee Homepage: https://gitee.com/stevejrong1024
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *        https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.stevejrong.waiter.aa.component.infrastructure.util;

import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.web.server.ServerWebExchange;

import reactor.core.publisher.Mono;

/**
 * 工具类 - 响应式HTTP请求/响应工具类
 * 
 * @author Steve Jrong
 * @since 1.0
 */
public final class ReactiveHttpExchangeUtil {

	/**
	 * 获取响应式Http请求对象
	 * 
	 * @return 响应式ServerHttpRequest对象
	 */
	public static Mono<ServerHttpRequest> getReactiveHttpRequest() {
		return Mono.deferContextual(context -> 
					Mono.just(context.get(ServerWebExchange.class).getRequest())
				);
	}
	
	/**
	 * 获取响应式Http响应对象
	 * 
	 * @return 响应式ServerHttpResponse对象
	 */
	public static Mono<ServerHttpResponse> getReactiveHttpResponse() {
		return Mono.deferContextual(context -> 
					Mono.just(context.get(ServerWebExchange.class).getResponse())
				);
	}
}
